/**
* 勋章墙页
* path:'/medalswall'，query:{userType:'必传'}
* userType=Constant.user.SELF 自己； userType=Constant.user.OTHER 他人；
*/
<template>
  <div class="situation medals-wall">
    <header-top :option="headerOption"></header-top>
    <overview :userType="userType" :userHead="userHead" :nickname="nickname" :walletTotal="walletTotal"></overview>
    <div class="wave">
      <img src="~assets/images/bowen@3x.png" width="100%" height="40px">
    </div>
    <div class="messages">
      <div class="content">
        <div class="tips">亲们，勋章任务请在第二天查看结果哦~</div>
      </div>
    </div>
    <medals :userType="userType" :configType="configType[0]" title="名誉勋章"></medals>
    <medals :userType="userType" :configType="configType[1]" title="珍稀勋章"></medals>
    <medals :userType="userType" :configType="configType[2]" title="土豪勋章"></medals>
  </div>
</template>

<script>
  import RemoteDAO from 'common/remoteDAO'
  import CommonUtil from 'common/common.util'
  import LocalDAO from 'common/localDAO'
  import Constant from 'common/constant'
  import _ from 'underscore'
  import HeaderTop from 'components/HeaderTop'
  import OverView from 'components/dynamic/medalswall/OverView'
  import Medals from 'components/dynamic/medalswall/Medals'

  export default {
    data () {
      return {
        headerOption: {
          title: '勋章墙',
          leftBtn: Constant.leftBtn.BACK,
          operations: [Constant.operation.SHARE],
          page:Constant.storage.SHARE_MEDALS_WALL
        },
        userCode:LocalDAO.getUserCode(),
        userType:Constant.user.OTHER,
        userHead:CommonUtil.getDefaultUserHead(LocalDAO.getUserCode()),
        nickname:'--',
        walletTotal:'--',
        configType: ['MYXZ','ZXXZ','THXZ'],
        error: ''
      }
    },
    components:{
      'header-top': HeaderTop,
      'overview': OverView,
      'medals':Medals
    },
    created: function () {
      this.fetchData();
      this.$root.eventHub.$on('getWalletTotal',(walletTotal)=>{
        this.walletTotal = walletTotal;
      })
    },
    methods: {
      fetchData () {
        var userType = this.$route.query.userType;
        if (userType == Constant.user.SELF) {
          this.headerOption.title = "我的勋章墙";
          this.userHead = LocalDAO.getUserHead();
          this.nickname = LocalDAO.getNickname();
          this.walletTotal = LocalDAO.getWalletTotal();
          this.$store.dispatch('setWallTotal',LocalDAO.getWalletTotal())
        } else if (userType == Constant.user.OTHER) {
          this.headerOption.title = "TA的勋章墙";
          this.userHead = LocalDAO.getOtherUserHead();
          this.nickname = LocalDAO.getOtherNickname();
          this.walletTotal = LocalDAO.getOtherWalletTotal();
        }
        this.userType = userType;
        // 更新分享页数据
        var shareMedalsWallPage = LocalDAO.getShareMedalsWall();
        shareMedalsWallPage.adDownload = {userCode:this.userCode};
        LocalDAO.setShareMedalsWall(shareMedalsWallPage);

        var shareMedalPage = LocalDAO.getShareMedal();
        shareMedalPage.adDownload = {userCode: this.userCode};
        LocalDAO.setShareMedal(shareMedalPage);

        var shareMedalsWall = LocalDAO.getShareMedalsWall();
        shareMedalsWall.overview.userHead = this.userHead;
        shareMedalsWall.overview.walletTotal = this.walletTotal;
        shareMedalsWall.overview.nickname = this.nickname;
        LocalDAO.setShareMedalsWall(shareMedalsWall);

      }
    }
  }
</script>
